package com.wangzhixuan.apiController;

import java.lang.reflect.InvocationTargetException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wangzhixuan.commons.base.ApiBaseController;
import com.wangzhixuan.commons.constant.ApiCode;
import com.wangzhixuan.model.JobBaseInfo;
import com.wangzhixuan.service.IJobBaseInfoService;

/**
 * <p>
 *   前端控制器
 * </p>
 * @author zhixuan.wang
 * @since 2017-07-16
 */
@Controller
@RequestMapping("/api/jobBaseInfo")
public class JobBaseInfoApiController extends ApiBaseController {
    
    @Autowired private IJobBaseInfoService jobBaseInfoService;
    
    /**
     * 添加
     * 依赖前端接口设计
     * @param 
     * @return
     * @throws InvocationTargetException 
     * @throws IllegalAccessException 
     */
    @RequestMapping("/addJobBaseInfo")
    @ResponseBody
    public Object addJobBaseInfo(@RequestBody JobBaseInfo jobBaseInfo) throws IllegalAccessException, InvocationTargetException {
    	boolean b = jobBaseInfoService.insertJobBaseInfo(jobBaseInfo);
        if (b) {
        	return renderSuccess(ApiCode.CODE_200, "成功");
        } else {
        	return renderError(ApiCode.CODE_500, "添加失败");
        }
    }

    /**
     * 删除
     * @param id
     * @return
     * 删除先不处理，因为删除的时候需要删除相关的个个子表
     */
//    @RequestMapping("/deleteJobBaseInfo")
//    @ResponseBody
//    public Object deleteJobBaseInfo(Long id) {
//        boolean b = jobBaseInfoService.deleteJobBaseInfoById(id);
//        if (b) {
//        	return renderSuccess(ApiCode.CODE_200, "成功");
//        } else {
//        	return renderError(ApiCode.CODE_500, "删除失败");
//        }
//    }

    /**
     * 编辑
     * 依赖前端接口设计
     * @param 
     * @return
     * @throws InvocationTargetException 
     * @throws IllegalAccessException 
     */
    @RequestMapping("/editJobBaseInfo")
    @ResponseBody
    public Object editJobBaseInfo(@RequestBody JobBaseInfo jobBaseInfo) throws IllegalAccessException, InvocationTargetException {
        boolean b = jobBaseInfoService.updateJobBaseInfoById(jobBaseInfo);
        if (b) {
        	return renderSuccess(ApiCode.CODE_200, "成功");
        } else {
        	return renderError(ApiCode.CODE_500, "编辑失败");
        }
    }
    
}
